<?php
class MemberWithdrawModel extends Model{
	private $table1 = 'member_withdraw';
	private $table2 = 'membership';
	
	/**
	 * 获取对应用户提现的总金额
	 * @param $uid
	 */
	public function getAllMoney($uid){
		$sql = "SELECT sum(mw.money) as total FROM ".$this->table1." mw WHERE mw.uid=".$uid." AND flag=1";
		//echo $sql;die;
		$result = M($this->table1)->query($sql);
		//var_dump($result);die;
		return $result[0]['total'];
		
	}
	
	/**
	 * 获取提现记录
	 * @param $uid $order $limit
	 */
	public function getW($uid,$order,$limit){
		// M($this->table1)->where($where)->order($order)->limit($limit);
		$sql = "SELECT * FROM ".$this->table1." WHERE uid=".$uid." ORDER BY ".$order." LIMIT ".$limit;
		//echo $sql;die;
		return M($this->table1)->query($sql);
		// echo M($this->table1)->getLastSql();die;
	}
	
	/**
	 * 按照天数获取产品个数
	 * @param string $where
	 */
	public function getWcByday($where=1,$limit,$order){
		if($limit){
			$sql = "select DATE_FORMAT(w.withdraw_date,'%Y-%m-%d') day, count(*) c from ".$this->table1." w LEFT JOIN ".$this->table2." m ON w.uid=m.uid WHERE ".$where." group by DATE_FORMAT(w.withdraw_date,'%Y%m%d') ORDER BY ".$order." LIMIT ".$limit;
		}else{
			$sql = "select DATE_FORMAT(w.withdraw_date,'%Y-%m-%d') day, count(*) c from ".$this->table1." w LEFT JOIN ".$this->table2." m ON w.uid=m.uid WHERE ".$where." group by DATE_FORMAT(w.withdraw_date,'%Y%m%d') ORDER BY ".$order;
		}
		//echo $sql;die;
		return M($this->table1)->query($sql);
	}
	
	
	/**
	 * 获取按天数获取产品的个数
	 * @param string  $where
	 */
	public function getWc($where=1){
		$sql = "select DATE_FORMAT(w.withdraw_date,'%Y-%m-%d') day, count(*) c from ".$this->table1." w LEFT JOIN ".$this->table2." m ON w.uid=m.uid WHERE ".$where." group by DATE_FORMAT(w.withdraw_date,'%Y%m%d') ";
		$result = M($this->table1)->query($sql);
		return count($result);
	}
	/**
	 * 根据天数获取产品详情
	 * @param string $where
	 */
	public function getWcDetail($where=1,$limit,$order){
		if($limit){
			$sql = "select w.*,m.name,m.member_id from ".$this->table1." w LEFT JOIN ".$this->table2." m ON w.uid=m.uid WHERE ".$where." ORDER BY ".$order." LIMIT ".$limit;
		}else{
			$sql = "select w.*,m.name,m.member_id from ".$this->table1." w LEFT JOIN ".$this->table2." m ON w.uid=m.uid WHERE ".$where." ORDER BY ".$order;
		}
		//echo $sql;die;
		return M($this->table1)->query($sql);
	}
}